﻿// JScript 文件
var m_xmin = 0, m_ymin = 0, m_xmax = 0, m_ymax = 0;
var m_oldxmin = 0, m_oldymin = 0, m_oldxmax = 0, m_oldymax = 0;
var m_Height = 0, m_Width = 0, m_pixelX = 0, m_pixelY = 0;
var m_widx = 0, m_widy = 0;
var m_ActieTool=0;
var m_MouseDown = new MouseDot(0,0)
var m_MouseUp = new MouseDot(0,0)

var m_Fnt;
var m_Tal;

var m_fs = 4;    //管孔编码初始字体大小
var m_h = 1.2;   //节点展开图放大、缩小倍数
var m_ovalList = new Array();

var m_bodyWidth = 0;
var m_bodyHeight = 0;


function MouseDot(x, y)
{
   this.x = x;
   this.y = y;
}

//管孔信息结构体
function ovalItem(id,useInfo)
{ 
    this.id      = id;          //管孔ID
    this.useInfo = useInfo;     //管孔占用信息
}

function DrawMap()
{
    var Major = $("HidMajor").value;
    var Minor = $("HidMinor").value;
    var GddNo = $("HidGddNo").value;
    
    var url = "/handlers/MapHandler.ashx?";
    var mapCfg   = CtnTrans.getXml(url, "POST", "method=getCfg");
    var m = mapCfg.selectSingleNode("m");
    m_IsJwd    = parseInt(m.getAttribute("isjwd")) == 1 ? true : false;

    this.ToolBar();
    
    createTopDiv();     //创建窗口操作DIV（最顶层DIV）
    window.RectPen.Container = $("allInfoDiv"); //设置矩形画笔绘画容器
    getEntRectList(Major, Minor, GddNo);
}

//创建窗口操作DIV
function createTopDiv()
{
    var $body = window.document.getElementsByTagName("body")[0];
    redrawDiv();
    var allInfoDiv=document.createElement("DIV");
	allInfoDiv.id="allInfoDiv";
	allInfoDiv.style.position="absolute";
	allInfoDiv.style.zIndex="8000";
	allInfoDiv.style.left = "0px";
	allInfoDiv.style.top  = "0px";
	allInfoDiv.style.overflow = "hidden";
	allInfoDiv.style.width = m_bodyWidth + "px";
	allInfoDiv.style.height = m_bodyHeight + "px";
	allInfoDiv.style.backgroundColor = "white";
	//allInfoDiv.style.backgroundColor = "red";
	allInfoDiv.style.filter = "alpha(opacity=10)";
	if($body) $body.appendChild(allInfoDiv);
}

function redrawDiv()
{
    var $body = window.document.getElementsByTagName("body")[0];
	if(CtnBrowser.IE)
	{
	    m_bodyWidth  = $body.clientWidth;
	    m_bodyHeight  = document.documentElement.clientHeight;
	}
	else if(CtnBrowser.FF)
	{
	    m_bodyWidth  = document.documentElement.clientWidth;
	    m_bodyHeight  = document.documentElement.clientHeight;
	}
}

this.ToolBar = function()
{
    var toolBar = document.createElement("DIV");
    toolBar.id  = "toolBar";
    toolBar.style.display = "block";
    toolBar.style.position = "absolute";
    toolBar.style.zIndex="10000";
    var bd = document.getElementsByTagName("body")[0];
    toolBar.style.left = parseInt(bd.clientWidth)- 140 + "px";
    toolBar.style.width = 140 + "px";
    toolBar.style.height = 26 + "px";
    toolBar.style.top  = 0 + "px";
    toolBar.innerHTML = "<img src=\"../images/zoomin_expand.gif\" onmousedown=\"javascript:this.style.width='25px'\" onmouseup=\"javascript:this.style.width='26px'\" style=\"width:26px;left:5px;position:absolute;cursor:hand;\" onclick=\"javascript:zoomInWnd()\" alt=\"放大窗口\"/>" +
                      "<img src=\"../images/zoomout_expand.gif\" onmousedown=\"javascript:this.style.width='25px'\" onmouseup=\"javascript:this.style.width='26px'\" style=\"width:26px;left:31px;position:absolute;cursor:hand;\" onclick=\"javascript:zoomOutWnd()\" alt=\"缩小窗口\"/>" +
                      "<img src=\"../images/move_expand.gif\" onmousedown=\"javascript:this.style.width='25px'\" onmouseup=\"javascript:this.style.width='26px'\" style=\"width:26px;left:57px;position:absolute;cursor:hand;\" onclick=\"javascript:moveWnd()\" alt=\"移动窗口\"/>" +
                      "<img src=\"../images/refresh_expand.gif\"onmousedown=\"javascript:this.style.width='25px'\" onmouseup=\"javascript:this.style.width='26px'\" style=\"width:26px;left:83px;position:absolute;cursor:hand;\" onclick=\"javascript:resetWnd()\" alt=\"复位窗口\"/>" +
                      "<img src=\"../images/code_expand.gif\"onmousedown=\"javascript:this.style.width='25px'\" onmouseup=\"javascript:this.style.width='26px'\" style=\"width:26px;left:109px;position:absolute;cursor:hand;\" onclick=\"javascript:dispCode()\" alt=\"查看编码\"/>";
    toolBar.style.backgroundImage  = "url(../images/bg_expand1.gif)";
    toolBar.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=70)";
    bd.appendChild(toolBar);
}

function Onrightclick(evt)
{
    mc = new CtnMenuCtrl("mc");
    with(mc)
    {
        addEvent("放大窗口", "zoomInWnd()");
        addEvent("缩小窗口", "zoomOutWnd()");
        addEvent("移动窗口", "moveWnd()");
        addEvent("复位窗口", "resetWnd()");
        addEvent("查看编码", "dispCode()");
    }
    mc.show(evt);
    return false;
}

//窗口放大
function zoomInWnd()
{
    $("allInfoDiv").onmousedown = function(evt)
    { 
        m_MouseDown.x  = event.clientX;
        m_MouseDown.y  = event.clientY;
        window.RectPener.OnMouseDown(); 
    };
    $("allInfoDiv").onmousemove = function(evt)
    { 
        window.RectPener.OnMouseMove(); 
    };
    $("allInfoDiv").onmouseup = function(evt)
    { 
        window.RectPener.OnMouseUp(); 
        m_MouseUp.x  = event.clientX;
        m_MouseUp.y  = event.clientY;
        
        var offstx = m_MouseUp.x - m_MouseDown.x;
        var offsty = m_MouseUp.y - m_MouseDown.y;
        
        if (offstx == 0 && offsty == 0)
        {
            return;
        }
        
        var x = $("group1").coordsize.x;
        var y = $("group1").coordsize.y;
        $("group1").coordsize=x/m_h+","+y/m_h;
     
        $("group1").style.fontSize=m_fs*m_h+"pt";
        m_fs=m_fs*m_h;
        
        var e = evt ? evt : event;
        if(CtnBrowser.IE)
        { 
            if(e.button == 1) //左键
            {
                $("rightdiv").style.visibility = "hidden";
                
                var xy = window.RectPen.GetWindowCenXY();
                window.RectPener.DelGragph();
                var cx = xy[0];                                   
                var cy = xy[1];

                var offsetX = m_bodyWidth/2 - cx;
                var offsetY = m_bodyHeight/2 - cy;
                $("group1").style.left = parseInt($("group1").style.left) + offsetX + "px";
                $("group1").style.top = parseInt($("group1").style.top) + offsetY + "px";
                redrawDiv();
            }
            if(e.button == 2) //右键
            {
                $("rightdiv").style.visibility = "visible";
            }
        }
        if(CtnBrowser.FF)
        {
            if(e.button == 0) //左键
            {
                $("rightdiv").style.visibility = "hidden";
                
                var xy = window.RectPen.GetWindowCenXY();
                window.RectPener.DelGragph();
                var cx = xy[0];                                   
                var cy = xy[1];

                var offsetX = m_bodyWidth/2 - cx;
                var offsetY = m_bodyHeight/2 - cy;
                $("group1").style.left = parseInt($("group1").style.left) + offsetX + "px";
                $("group1").style.top = parseInt($("group1").style.top) + offsetY + "px";
                redrawDiv();
            }
            if(e.button == 2) //右键
            {
                $("rightdiv").style.visibility = "visible";
            }
        }   
    };
}

//窗口缩小
function zoomOutWnd()
{
    $("allInfoDiv").onmousedown = function(evt)
    { 
        m_MouseDown.x  = event.clientX;
        m_MouseDown.y  = event.clientY;
        window.RectPener.OnMouseDown(); 
    };
    $("allInfoDiv").onmousemove = function(evt)
    { 
        window.RectPener.OnMouseMove(); 
    };
    $("allInfoDiv").onmouseup = function(evt)
    { 
        window.RectPener.OnMouseUp(); 
        m_MouseUp.x  = event.clientX;
        m_MouseUp.y  = event.clientY;
        
        var offstx = m_MouseUp.x - m_MouseDown.x;
        var offsty = m_MouseUp.y - m_MouseDown.y;
        
        if (offstx == 0 && offsty == 0)
        {
            return;
        }
        
        var x = $("group1").coordsize.x;
        var y = $("group1").coordsize.y;
        if (parseInt(x) >= 900 && parseInt(y) >= 900)
        {
            hideWord();
            top.CtnDlg.msg("窗口已达默认最小尺寸！");
            return;
        }
        $("group1").coordsize=x*m_h+","+y*m_h;
     
        $("group1").style.fontSize=m_fs/m_h+"pt";
        m_fs=m_fs/m_h;
        
        var e = evt ? evt : event;
        if(CtnBrowser.IE)
        { 
            if(e.button == 1) //左键
            {
                $("rightdiv").style.visibility = "hidden";
                
                var xy = window.RectPen.GetWindowCenXY();
                window.RectPener.DelGragph();
                var cx = xy[0];                                   
                var cy = xy[1];

                var offsetX = m_bodyWidth/2 - cx;
                var offsetY = m_bodyHeight/2 - cy;
                $("group1").style.left = parseInt($("group1").style.left) + offsetX + "px";
                $("group1").style.top = parseInt($("group1").style.top) + offsetY + "px";
                redrawDiv();
            }
            if(e.button == 2) //右键
            {
                $("rightdiv").style.visibility = "visible";
            }
        }
        if(CtnBrowser.FF)
        {
            if(e.button == 0) //左键
            {
                $("rightdiv").style.visibility = "hidden";
                
                var xy = window.RectPen.GetWindowCenXY();
                window.RectPener.DelGragph();
                var cx = xy[0];                                   
                var cy = xy[1];

                var offsetX = m_bodyWidth/2 - cx;
                var offsetY = m_bodyHeight/2 - cy;
                $("group1").style.left = parseInt($("group1").style.left) + offsetX + "px";
                $("group1").style.top = parseInt($("group1").style.top) + offsetY + "px";
                redrawDiv();
            }
            if(e.button == 2) //右键
            {
                $("rightdiv").style.visibility = "visible";
            }
        }   
    };
}

//窗口移动
function moveWnd()
{
    $("allInfoDiv").show();
    $("allInfoDiv").onmousedown = function(evt)
    {
        m_MouseDown.x  = event.clientX;
        m_MouseDown.y  = event.clientY;
    };
    $("allInfoDiv").onmousemove = function(evt){};
    $("allInfoDiv").onmouseup = function(evt)
    { 
        var e = evt ? evt : event;
        if(CtnBrowser.IE)
        { 
            if(e.button == 1) //左键
            {
                $("rightdiv").style.visibility = "hidden";
                m_MouseUp.x  = event.clientX;
                m_MouseUp.y  = event.clientY;
                
                var offstx = m_MouseUp.x - m_MouseDown.x;
                var offsty = m_MouseUp.y - m_MouseDown.y;

                $("group1").style.left = parseInt($("group1").style.left) + offstx + "px";
                $("group1").style.top = parseInt($("group1").style.top) + offsty + "px";
                redrawDiv();
            }
            if(e.button == 2) //右键
            {
                $("rightdiv").style.visibility = "visible";
            }
        }
        if(CtnBrowser.FF)
        {
            if(e.button == 0) //左键
            {
                $("rightdiv").style.visibility = "hidden";
                m_MouseUp.x  = event.clientX;
                m_MouseUp.y  = event.clientY;
                
                var offstx = m_MouseUp.x - m_MouseDown.x;
                var offsty = m_MouseUp.y - m_MouseDown.y;

                $("group1").style.left = parseInt($("group1").style.left) + offstx + "px";
                $("group1").style.top = parseInt($("group1").style.top) + offsty + "px";
                redrawDiv();
            }
            if(e.button == 2) //右键
            {
                $("rightdiv").style.visibility = "visible";
            }
        }   
    };
}

//窗口复位
function resetWnd()
{
    hideCode();
    $("rightdiv").style.visibility = "hidden";

    $("group1").style.left = 0 + "px";
    $("group1").style.top = 0 + "px";
    
    $("group1").coordsize = "900,900";
    redrawDiv();
}

function SetTitle(GddBM, TalBm, FntBm, Qsjmh, Zzjmh)
{
    $("GddDesc").innerText = "管道段展开图(" + GddBM[0].text + ")";
    var jm1,jm2;
    
    switch (Qsjmh[0].text)
    {
    case "A":
        jm1 = "北";
        break;
    case "B":
        jm1 = "东";
        break;
    case "C":
        jm1 = "南";
        break;
    case "D":
        jm1 = "西";
        break;
    default :
        break;
    }
    switch (Zzjmh[0].text)
    {
    case "A":
        jm2 = "北";
        break;
    case "B":
        jm2 = "东";
        break;
    case "C":
        jm2 = "南";
        break;
    case "D":
        jm2 = "西";
        break;
    default:
        break;
    }
    $("PntDesc1").innerText = "前点编码：" + m_Fnt[0].text + "(井面：" + jm1 + ")";
    $("PntDesc2").innerText = "后点编码：" + m_Tal[0].text + "(井面：" + jm2 + ")";
}


function dispCode()
{
    if (m_PntNo == 0)
    {
        top.CtnDlg.warning("尚未录入任何管孔信息！");
        return;
    }
    if (m_ovalList.length != 0)
    {
        $("group1").style.left = 0 + "px";
        $("group1").style.top = 0 + "px";
        $("group1").coordsize="362,362";
        $("group1").style.fontSize="9.95328pt";
        m_fs = 9.95328;
        
        for (var i = 0; i < m_ovalList.length; i ++)
        {
            switch (m_ovalList[i].useInfo)
           {
	          case "0":  //空闲 
	          case "1":  //占用（电缆段蓝色，光缆段为红色）
	          case "3":   //坏 (蓝色，画叉）
                 idStr = "spanGk1"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "visible";
                 idStr = "spanGk2"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "visible";	     
	          break;
        	  
	          case "2":  //预占(绿色)
	             idStr = "spanGk11"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "visible";
                 idStr = "spanGk12"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "visible";
                 idStr = "spanGk21"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "visible";
                 idStr = "spanGk22"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "visible";	    
	             break;
	          default:
	          break;
	        }
        }
    }
}

function hideCode()
{
    if (m_ovalList.length != 0)
    {
        $("group1").coordsize="362,362";
        $("group1").style.fontSize="9.95328pt";
        m_fs = 9.95328;
        
        for (var i = 0; i < m_ovalList.length; i ++)
        {
            switch (m_ovalList[i].useInfo)
           {
	          case "0":  //空闲 
	          case "1":  //占用（电缆段蓝色，光缆段为红色）
	          case "3":   //坏 (蓝色，画叉）
                 idStr = "spanGk1"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "hidden";
                 idStr = "spanGk2"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "hidden";	     
	          break;
        	  
	          case "2":  //预占(绿色)
	             idStr = "spanGk11"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "hidden";
                 idStr = "spanGk12"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "hidden";
                 idStr = "spanGk21"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "hidden";
                 idStr = "spanGk22"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "hidden";	    
	             break;
	          default:
	          break;
	        }
        }
    }
}

function hideWord()
{
    if (m_ovalList.length != 0)
    {
        for (var i = 0; i < m_ovalList.length; i ++)
        {
            switch (m_ovalList[i].useInfo)
           {
	          case "0":  //空闲 
	          case "1":  //占用（电缆段蓝色，光缆段为红色）
	          case "3":   //坏 (蓝色，画叉）
                 idStr = "spanGk1"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "hidden";
                 idStr = "spanGk2"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "hidden";	     
	          break;
        	  
	          case "2":  //预占(绿色)
	             idStr = "spanGk11"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "hidden";
                 idStr = "spanGk12"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "hidden";
                 idStr = "spanGk21"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "hidden";
                 idStr = "spanGk22"+m_ovalList[i].id;
                 $(idStr).style.zIndex = 10000;
                 $(idStr).style.visibility = "hidden";	    
	             break;
	          default:
	          break;
	        }
        }
    }
}

var m_PntNo = 0;
var m_TalScale;
var m_FntScale;
function InitMapWnd(response)
{
    if (!CtnError.validate(response.responseText))
    {
        CtnError.show();
        return;
    }
    var XmlDoc = CtnXML.getXmlDoc();
    
    var vAGrid = 200;
    var vOffsetX = 25; //细微的偏移参数

    var vOffsetY = 5; //细微的偏移参数

    var vOffset = 50;
    
    m_PntNo = 0;
    
    //绘制外框
    $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "black", vOffset, vOffset, 0          , 0, vAGrid     , 0, 0)));
    $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", vOffset, vOffset, vAGrid     , 0, vAGrid * 2 , 0, 1)));
    $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "black", vOffset, vOffset, vAGrid * 2 , 0, vAGrid * 3 , 0, 0)));
	
    $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "black", vOffset, vOffset, 0          , vAGrid, vAGrid     , vAGrid, 0)));
    $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", vOffset, vOffset, vAGrid     , vAGrid, vAGrid * 2 , vAGrid, 1)));
    $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "black", vOffset, vOffset, vAGrid * 2 , vAGrid, vAGrid * 3 , vAGrid, 0)));
	
    $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "black", vOffset, vOffset * 2, 0          , vAGrid, vAGrid     , vAGrid, 0)));
    $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", vOffset, vOffset * 2, vAGrid     , vAGrid, vAGrid * 2 , vAGrid, 1)));
    $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "black", vOffset, vOffset * 2, vAGrid * 2 , vAGrid, vAGrid * 3 , vAGrid, 0)));
	
    $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "black", vOffset, vOffset * 2, 0          , vAGrid * 2, vAGrid     , vAGrid * 2, 0)));
    $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", vOffset, vOffset * 2, vAGrid     , vAGrid * 2, vAGrid * 2 , vAGrid * 2, 1)));
    $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "black", vOffset, vOffset * 2, vAGrid * 2 , vAGrid * 2, vAGrid * 3 , vAGrid * 2, 0)));	
	
    $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", vOffset, vOffset, vAGrid, 0, vAGrid, vAGrid, 1)));
    $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", vOffset, vOffset * 2, vAGrid,vAGrid, vAGrid, vAGrid * 2, 1)));
    $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", vOffset, vOffset, vAGrid * 2,0, vAGrid * 2, vAGrid, 1)));
    $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", vOffset, vOffset * 2, vAGrid * 2,vAGrid, vAGrid * 2, vAGrid * 2, 1)));
	
    //绘制管孔
    if (XmlDoc != null)
    {
        XmlDoc.loadXML(response.responseText);
        codeXml = XmlDoc;
        var nodes = XmlDoc.selectNodes('NewDataSet'); 
	    if(nodes.length == 0)
	    {
            return;
        }
	   else
	   {

	      for (i = 0; i < nodes.length; ++i)
	      {	      	      
	      
///////////////////需要分析电缆对应那些ＺＣＮＯ和光缆对应那些ＺＣＮＯ
	         var lstDl = new Array();//电缆所对应的ZCNO列表
	         var lstGl = new Array();//光缆所对应的ZCNO列表
	         var vPnt = nodes[i].selectNodes("TeDld"); //
             for (l = 0; l < vPnt.length; ++l)
             {
	              var vDlGkID = vPnt[l].selectNodes("ZCNO");
	              lstDl.push(vDlGkID[0].text);
	         }
	         var vPnt = nodes[i].selectNodes("TeGld"); //
	         for (l = 0; l < vPnt.length; ++l)
             {
	              var vDlGkID = vPnt[l].selectNodes("ZCNO");
	              lstGl.push(vDlGkID[0].text);
	         }
//////////////////////////////////////////////////////////////////////	          
	          var vPnt = nodes[i].selectNodes("TeGdd"); //
	          for (l = 0; l < vPnt.length; ++l)
	          {
	              var vBM   = vPnt[l].selectNodes("BM");
	              var vMC   = vPnt[l].selectNodes("MC");
				  var vQsjmh = vPnt[l].selectNodes("QSJMH");
				  var vZzjmh = vPnt[l].selectNodes("ZZJMH");
	          }	        
	             	      
	          var vTal = nodes[i].selectNodes("TeTal"); //
	          var vTalRad;
	          for (l = 0; l < vTal.length; ++l)
	          {
	              var bz1 = vTal[l].selectNodes("TAL");
	              m_Tal = vTal[l].selectNodes("TAL");
	              vTalRad = vTal[l].selectNodes("RAD");
	          }	   
	          m_TalScale = 100/parseFloat(vTalRad[0].text);  
	          var vFnt = nodes[i].selectNodes("TeFnt"); //
	          var vFntRad;
	          for (l = 0; l < vFnt.length; ++l)
	          {
	              var bz2 = vFnt[l].selectNodes("FNT");
	              m_Fnt = vFnt[l].selectNodes("FNT");
	              vFntRad = vFnt[l].selectNodes("RAD");
	          }	   
	          m_FntScale = 100/parseFloat(vFntRad[0].text);
	          SetTitle(vBM, bz1, bz2, vQsjmh, vZzjmh);
	         // m_Fnt = bz1;
	           
	          var vPnt = nodes[i].selectNodes("TePip"); 
	          //大管孔              m_PntNo = m_PntNo + vPnt.length;
	          for (l = 0; l < vPnt.length; ++l)
	          {
	              var vId  = vPnt[l].selectNodes("ID0");
	              var vX0  = vPnt[l].selectNodes("X0");
				  var vY0  = vPnt[l].selectNodes("Y0");
				  var vX1  = vPnt[l].selectNodes("X1");
				  var vY1  = vPnt[l].selectNodes("Y1");
				  var vRAD0 = vPnt[l].selectNodes("RAD0");
				  var vRAD1 = vPnt[l].selectNodes("RAD1");
				  var vUsed = vPnt[l].selectNodes("USED");
				  var vParent = vPnt[l].selectNodes("INPIPNO");
				  var vPipCz  = vPnt[l].selectNodes("PipCz");
				  var vBM1  = vPnt[l].selectNodes("GKBM1");
				  var vBM2  = vPnt[l].selectNodes("GKBM2");

				  if (vParent[0].text == "0")
				  {
				      var vDlFlag = 0;
				      var vGlFlag = 0;
				      var item = new ovalItem(vId[0].text,vUsed[0].text);
                      m_ovalList.push(item);
				      for (ll = 0; ll < lstDl.length; ++ll)
				      {
				        if (lstDl[ll] == vId[0].text)
				        {
				            DrawGkong($("divLinView"), vId, vX0, vY0,vBM1, vX1, vY1, vBM2,vRAD0, vRAD1, vUsed, vQsjmh, vZzjmh, 0.5, 21, vPipCz);
				            vDlFlag = 1;
				            break;
				        }
				      }
				      for (lll = 0; lll < lstGl.length; ++lll)
				      {
				        if (lstGl[lll] == vId[0].text)
				        {
				            DrawGkong($("divLinView"), vId, vX0, vY0,vBM1, vX1, vY1, vBM2,vRAD0, vRAD1, vUsed, vQsjmh, vZzjmh, 0.5, 31, vPipCz);
				            vGlFlag = 1;
				            break;
				        }
				      }
				      if (vDlFlag == 0 && vGlFlag == 0)
				      {
				           DrawGkong($("divLinView"), vId, vX0, vY0,vBM1, vX1, vY1, vBM2,vRAD0, vRAD1, vUsed, vQsjmh, vZzjmh, 0.5, 0, vPipCz);
				      }     
				  }						  
	          }	  	   
	          
	          //小管孔
	          for (j = 0; j < vPnt.length; ++j)
	          {
	              var vId  = vPnt[j].selectNodes("ID0");
	              var vX0  = vPnt[j].selectNodes("X0");
				  var vY0  = vPnt[j].selectNodes("Y0");
				  var vX1  = vPnt[j].selectNodes("X1");
				  var vY1  = vPnt[j].selectNodes("Y1");
				  var vRAD0 = vPnt[j].selectNodes("RAD0");
				  var vRAD1 = vPnt[j].selectNodes("RAD1");
				  var vUsed = vPnt[j].selectNodes("USED");
				  var vParent = vPnt[j].selectNodes("INPIPNO");
				  var vPipCz  = vPnt[j].selectNodes("PipCz");
				  var vBM1  = vPnt[j].selectNodes("GKBM1");
				  var vBM2  = vPnt[j].selectNodes("GKBM2");
				  
				  if (vParent[0].text != "0")
				  {
				      var vDlFlag = 0;
				      var vGlFlag = 0;
				      for (ll = 0; ll < lstDl.length; ++ll)
				      {
				        if (lstDl[ll] == vId[0].text)
				        {
				            DrawGkong($("divLinView"), vId, vX0, vY0,vBM1, vX1, vY1, vBM2,vRAD0, vRAD1, vUsed, vQsjmh, vZzjmh, 0.5, 21, vPipCz);
				            vDlFlag = 1;
				            break;
				        }
				      }
				      for (lll = 0; lll < lstGl.length; ++lll)
				      {
				        if (lstGl[lll] == vId[0].text)
				        {
				            DrawGkong($("divLinView"), vId, vX0, vY0,vBM1, vX1, vY1, vBM2,vRAD0, vRAD1, vUsed, vQsjmh, vZzjmh, 0.5, 31, vPipCz);
				            vGlFlag = 1;
				            break;
				        }
				      }
				      if (vDlFlag == 0 && vGlFlag == 0)
				      {
				           DrawGkong($("divLinView"), vId, vX0, vY0,vBM1, vX1, vY1, vBM2,vRAD0, vRAD1, vUsed, vQsjmh, vZzjmh, 0.5, 0, vPipCz);
				      }     
				  }			  
	          }	  	          
	          
	          //设置标题
             var vPnt = nodes[i].selectNodes("TeDld"); 
             for (l = 0; l < vPnt.length; ++l)
             {
                  var vID0   = vPnt[l].selectNodes("ID0");
                  var vBm  = vPnt[l].selectNodes("BM");
	              var vGkID = vPnt[l].selectNodes("ZCNO");
            	  
	              var vCirID1 =	"Gk1" + vGkID[0].text;
	              var vGK1 = document.getElementById(vCirID1);
            	  
	              vGK1.title += "电缆段：";
	              vGK1.title += vBm[0].text;
	              vGK1.title += "\n";
            	  
	              var vCirID2 =	"Gk2" + vGkID[0].text;
	              var vGK2 = document.getElementById(vCirID2);
            	  
	              vGK2.title += "电缆段：";
	              vGK2.title += vBm[0].text;
	              vGK2.title += "\n";
             }	   
             
             var vPnt = nodes[i].selectNodes("TeGld"); 
             for (l = 0; l < vPnt.length; ++l)
             {
                  var vID0   = vPnt[l].selectNodes("ID0");
                  var vBm  = vPnt[l].selectNodes("BM");
	              var vGkID = vPnt[l].selectNodes("ZCNO");
            	  
	              var vCirID1 =	"Gk1" + vGkID[0].text;
	              var vGK1 = document.getElementById(vCirID1);
            	  
	              vGK1.title += "光缆段：";
	              vGK1.title += vBm[0].text;
	              vGK1.title += "\n";
            	  
	              var vCirID2 =	"Gk2" + vGkID[0].text;
	              var vGK2 = document.getElementById(vCirID2);
            	  
	              vGK2.title += "光缆段：";
	              vGK2.title += vBm[0].text;
	              vGK2.title += "\n";
             }	   
	       }    
	   }
	   
//	   if (pntNo != 0)
//	   {
//	        ToolBar();     //绘制工具条
//	        //绘制外框
//	        $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "black", vOffset, vOffset, 0          , 0, vAGrid     , 0, 0)));
//	        $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", vOffset, vOffset, vAGrid     , 0, vAGrid * 2 , 0, 1)));
//	        $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "black", vOffset, vOffset, vAGrid * 2 , 0, vAGrid * 3 , 0, 0)));
//        	
//	        $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "black", vOffset, vOffset, 0          , vAGrid, vAGrid     , vAGrid, 0)));
//	        $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", vOffset, vOffset, vAGrid     , vAGrid, vAGrid * 2 , vAGrid, 1)));
//	        $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "black", vOffset, vOffset, vAGrid * 2 , vAGrid, vAGrid * 3 , vAGrid, 0)));
//        	
//	        $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "black", vOffset, vOffset * 2, 0          , vAGrid, vAGrid     , vAGrid, 0)));
//	        $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", vOffset, vOffset * 2, vAGrid     , vAGrid, vAGrid * 2 , vAGrid, 1)));
//	        $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "black", vOffset, vOffset * 2, vAGrid * 2 , vAGrid, vAGrid * 3 , vAGrid, 0)));
//        	
//	        $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "black", vOffset, vOffset * 2, 0          , vAGrid * 2, vAGrid     , vAGrid * 2, 0)));
//	        $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", vOffset, vOffset * 2, vAGrid     , vAGrid * 2, vAGrid * 2 , vAGrid * 2, 1)));
//	        $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "black", vOffset, vOffset * 2, vAGrid * 2 , vAGrid * 2, vAGrid * 3 , vAGrid * 2, 0)));	
//        	
//	        $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", vOffset, vOffset, vAGrid, 0, vAGrid, vAGrid, 1)));
//	        $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", vOffset, vOffset * 2, vAGrid,vAGrid, vAGrid, vAGrid * 2, 1)));
//	        $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", vOffset, vOffset, vAGrid * 2,0, vAGrid * 2, vAGrid, 1)));
//	        $("divLinView").appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", vOffset, vOffset * 2, vAGrid * 2,vAGrid, vAGrid * 2, vAGrid * 2, 1)));
//	   }
//	   else
//	   {
//	        top.CtnDlg.warning("相关管道段中尚未录入任何管孔信息！");
//            return;
//	   }
   }
}

//rate 绘制管孔占用时，填充颜色占孔半径的比例

function DrawGkong(vDivGroup, vId, vX0, vY0, vBM1,vX1, vY1,vBM2,vRAD0, vRAD1, vUsed, vQsjmh, vZzjmh, rate, type, pipcz)
{
      var vAGrid = 200;
      var vOffset = 50; //细微的偏移参数

      switch(parseInt(pipcz[0].text))
      {
       case 1:
         pipcz = "RGB(128,255,255)";
       break;
       case 2:
         pipcz = "RGB(128,128,192)";
       break;
       case 3:
         pipcz = "RGB(187,187,187)";
       break;
       case 4:
         pipcz = "RGB(50,192,153)";
       break;
       case 5:
         pipcz = "RGB(136,0,136)";
       break;
       case 6:
         pipcz = "RGB(234,234,0)";
       break;
      }
      var vtmpRAD2 = parseFloat(vRAD0[0].text)
	  var vtmpX0 = parseFloat(vX0[0].text);
	  var vtmpY0 = parseFloat(vY0[0].text);
	  var vtmpRAD0 = parseFloat(vRAD0[0].text);
	  var vtmpX1 = parseFloat(vX1[0].text);
	  var vtmpY1 = parseFloat(vY1[0].text);
	  var vtmpRAD1 = parseFloat(vRAD1[0].text);
	  
	  
	  //看对端是不是引上点,要是引上点就*3.75
	  if (vtmpRAD0 != vtmpRAD1)
	  {
	        if (vtmpRAD0 > vtmpRAD1)
	        {
	            vtmpRAD1 = vtmpRAD1 * 3.75;
	            vtmpX1   = vtmpX1   * 3.75;
	            vtmpY1   = vtmpY1   * 3.75;
	        }
	        else
	        {
	            vtmpRAD0 = vtmpRAD0 * 3.75;
	            vtmpX0   = vtmpX0   * 3.75;
	            vtmpY0   = vtmpY0   * 3.75;
	        }
	  }
	  
	  var dot0 = convert(vQsjmh[0].text, vtmpX0, vtmpY0);  
	  var dot1 = convert(vZzjmh[0].text, vtmpX1, vtmpY1);  


	  if (m_IsJwd == false)
	  {
	      vtmpX0 = dot0[0] * vAGrid + vAGrid / 2 + vAGrid + vOffset;     
	      vtmpY0 = (dot0[1] * vAGrid - vAGrid * 1.5) * (-1) + vOffset;   
	      vtmpRAD0 = vtmpRAD0 * vAGrid;				  
    	  
	      vtmpX1 = dot1[0] * vAGrid + vAGrid / 2 + vAGrid + vOffset;
	      vtmpY1 = (dot1[1] * vAGrid - vAGrid * 1.5 - vAGrid) * (-1) + vOffset * 2;
	      vtmpRAD1 = vtmpRAD1 * vAGrid;
	  }
	  else
	  {
          vtmpX0 = dot0[0]*m_TalScale + 300 + vOffset;     
          vtmpY0 = (-1)*dot0[1] * m_TalScale + 200 + vOffset;   
          vtmpRAD0 = vtmpRAD0 * m_TalScale;
          
          vtmpX1 = dot1[0]*m_FntScale + 300 + vOffset;
	      vtmpY1 = (-1)*dot1[1] * m_FntScale + 400 + vOffset * 2;
	      vtmpRAD1 = vtmpRAD1 * m_FntScale;
	  }
	  
	  //绘制管孔;
	  switch (vUsed[0].text)
	  {
	  case "0":  //空闲 
         vDivGroup.appendChild(MakeADiv("Cir", "Pnt"+vId[0].text, makeCirStr("Gk1"+vId[0].text , 0, pipcz, vtmpX0, vtmpY0, vtmpRAD0, vBM1[0].text)));	  
	     vDivGroup.appendChild(MakeADiv("Cir", "Pnt"+vId[0].text, makeCirStr("Gk2"+vId[0].text , 0, pipcz, vtmpX1, vtmpY1, vtmpRAD1, vBM2[0].text)));	  
	  break;
	  case "1":  //占用（电缆段蓝色，光缆段为红色）
         vDivGroup.appendChild(MakeADiv("Cir", "Pnt"+vId[0].text, makeCirStr("Gk1"+vId[0].text , 0, pipcz, vtmpX0, vtmpY0, vtmpRAD0,vBM1[0].text)));	  
         vDivGroup.appendChild(MakeADiv("Cir", "Pnt"+vId[0].text, makeCirStr("Gk2"+vId[0].text , 0, pipcz, vtmpX1, vtmpY1, vtmpRAD1,vBM2[0].text)));
	     
         if (parseInt(type) == 21)
         {
            vDivGroup.appendChild(MakeADiv("Cir", "Pnt"+vId[0].text, makeCirStr("Gk1"+vId[0].text , 'blue', 'blue', vtmpX0, vtmpY0, vtmpRAD0 * rate, vBM1[0].text)));	 
            vDivGroup.appendChild(MakeADiv("Cir", "Pnt"+vId[0].text, makeCirStr("Gk2"+vId[0].text , 'blue', 'blue', vtmpX1, vtmpY1, vtmpRAD1 * rate, vBM2[0].text)));
         }
         else if(parseInt(type) == 31)   
         {
            vDivGroup.appendChild(MakeADiv("Cir", "Pnt"+vId[0].text, makeCirStr("Gk1"+vId[0].text , 'RGB(225,119,187)', 'RGB(225,119,187)', vtmpX0, vtmpY0, vtmpRAD0 * rate, vBM1[0].text)));
            vDivGroup.appendChild(MakeADiv("Cir", "Pnt"+vId[0].text, makeCirStr("Gk2"+vId[0].text , 'RGB(225,119,187)', 'RGB(225,119,187)', vtmpX1, vtmpY1, vtmpRAD1 * rate, vBM2[0].text)));	 
         }
	     break;
	  case "2":  //预占(绿色)
         vDivGroup.appendChild(MakeADiv("Cir", "Pnt"+vId[0].text, makeCirStr("Gk11"+vId[0].text , 0, pipcz, vtmpX0, vtmpY0, vtmpRAD0, vBM1[0].text)));	  
         vDivGroup.appendChild(MakeADiv("Cir", "Pnt"+vId[0].text, makeCirStr("Gk12"+vId[0].text , 'green', 'green', vtmpX0, vtmpY0, vtmpRAD0 * rate, vBM1[0].text)));
	     vDivGroup.appendChild(MakeADiv("Cir", "Pnt"+vId[0].text, makeCirStr("Gk21"+vId[0].text , 0, pipcz, vtmpX1, vtmpY1, vtmpRAD1, vId[0].text)));
	     vDivGroup.appendChild(MakeADiv("Cir", "Pnt"+vId[0].text, makeCirStr("Gk22"+vId[0].text , 'green', 'green', vtmpX1, vtmpY1, vtmpRAD1 * rate, vBM2[0].text)));
	     break;
	  case "3":   //坏 (蓝色，画叉）
          vDivGroup.appendChild(MakeADiv("Cir", "Pnt"+vId[0].text, makeCirStr("Gk1"+vId[0].text , 0, 'blue', vtmpX0, vtmpY0, vtmpRAD0, vBM1[0].text)));	  
	      vDivGroup.appendChild(MakeADiv("Cir", "Pnt"+vId[0].text, makeCirStr("Gk2"+vId[0].text , 0, 'blue', vtmpX1, vtmpY1, vtmpRAD1, vBM2[0].text)));
	      //绘制红色的交叉

	      vDivGroup.appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", 0, 0, vtmpX0 - vtmpRAD0, vtmpY0 - vtmpRAD0, vtmpX0 + vtmpRAD0, vtmpY0 + vtmpRAD0, 1)));
	      vDivGroup.appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", 0, 0, vtmpX0 - vtmpRAD0, vtmpY0 + vtmpRAD0, vtmpX0 + vtmpRAD0, vtmpY0 - vtmpRAD0, 1)));
	      vDivGroup.appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", 0, 0, vtmpX1 - vtmpRAD1, vtmpY1 - vtmpRAD0, vtmpX1 + vtmpRAD1, vtmpY1 + vtmpRAD1, 1)));
	      vDivGroup.appendChild(MakeADiv("Frame", 0, makeLinStr(0, "red", 0, 0, vtmpX1 - vtmpRAD1, vtmpY1 + vtmpRAD1, vtmpX1 + vtmpRAD1, vtmpY1 - vtmpRAD0, 1)));
	      break;
	  default:
	  break;
	  }
}

function convert(dir, x, y) //根据井面号将管孔坐标旋转成正北
{
    var dot = new Array();//{0,0}
    switch (dir)
    {
    case "A":
        dot[0] = x;
        dot[1] = y;
        return dot;
    case "B":
		dot[0] = (-1) * y;
		dot[1] = x;
        return dot;
    case "C":
		dot[0] = (-1) * x;
		dot[1] = (-1) * y;
        return dot;
    case "D":
		dot[0] = y;
		dot[1] = (-1) * x;
        return dot;
    default :
        return dot;
    }
}

function getEntRectList(Major, Minor, GddNo)
{
    $("divLinView").innerHTML = "";
    
    CtnTrans.Ajax("/main.ashx?","post","_method=GetGddZkt&GddNo=" + GddNo + "&Major=" + Major + "&Minor=" + Minor, InitMapWnd,null,{loading:true});
}





function ResetWnd()
{
    $("group1").style.width  = 900 + "px";
    $("group1").style.height = 900 + "px";

    $("group1").style.left = 0 + "px";
    $("group1").style.top = 0 + "px";
}



